<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>闭包</title>
</head>

<body>
    <div>
        闭包
    </div>
</body>
<script>
    var func = (function () {
        var cache = {}
        return function () {
            var args = Array.prototype.join.call(arguments, ',')
            if (cache[args]) {
                return cache[args];
            }
            var a = 1;
            for (var i = 0, l = arguments.length; i < l; i++) {
                a = a * arguments[i];
            }
            return cache[args] = a //{1,2,3:6}
        }
    })()
    console.log(func(1, 2, 3))


    var extent = function () {
        var value = 0;
        return {
            call: function () {
                value++;
                console.log(value);
            }
        }
    };
    var extent = extent();
    extent.call(); // 输出：1 
    extent.call(); // 输出：2 
    extent.call(); // 输出：3

    var extent = {
        value: 0,
        call: function () {
            this.value++;
            console.log(this.value);
        }
    };
    extent.call(); // 输出：1 
    extent.call(); // 输出：2 
    extent.call(); // 输出：3
</script>

</html>